package com.payment.ktb.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.payment.ktb.R;
import com.payment.ktb.model.BankType;
import com.squareup.picasso.Picasso;

import java.util.List;

/**
 * Created by admin on 2017/9/5.
 */

public class AddSettleBankCardAdapter extends BaseAdapter {

    Context mContext;
    List<BankType> listData;

    public AddSettleBankCardAdapter() {
    }

    public AddSettleBankCardAdapter(Context mContext, List<BankType> listData) {
        this.mContext = mContext;
        this.listData = listData;
    }

    @Override
    public int getCount() {
        return listData.size();
    }

    @Override
    public Object getItem(int i) {
        return listData.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {

        ViewHolder viewHolder = null;
        if (view == null) {
            viewHolder = new ViewHolder();
           view = View.inflate(mContext, R.layout.adapter_addsettlebankcard_item,null);
            viewHolder.tv_addsettlebankcard_bankname = (TextView) view.findViewById(R.id.tv_addsettlebankcard_bankname);
            viewHolder.iv_addsettlebankcard_bankname_nosel = (ImageView) view.findViewById(R.id.iv_addsettlebankcard_bankname_nosel);
            viewHolder.iv_addsettlebankcard_bankicon = (ImageView) view.findViewById(R.id.iv_addsettlebankcard_bankicon);
            view.setTag(viewHolder);
        }else {
            viewHolder = (ViewHolder) view.getTag();
        }
        viewHolder.tv_addsettlebankcard_bankname.setText(listData.get(i).getBankName());
        Picasso.with(mContext).load(listData.get(i).getBankIcon()).error(R.mipmap.payment_bank_logo).fit().into(viewHolder.iv_addsettlebankcard_bankicon);
        if (listData.get(i).isSelected()){
            viewHolder.iv_addsettlebankcard_bankname_nosel.setImageResource(R.mipmap.payment_btn_sel);
        }else {
            viewHolder.iv_addsettlebankcard_bankname_nosel.setImageResource(R.mipmap.payment_btn_nor);
        }
        return view;
    }


    class ViewHolder {
        TextView tv_addsettlebankcard_bankname;
        ImageView iv_addsettlebankcard_bankname_nosel;
        ImageView iv_addsettlebankcard_bankicon;
    }


}
